<?php
    include_once './config.php';
    $user = checkLogin(1);
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $action = $_POST['action'];
        $id = $_POST['id'];
        if($action == 'edit'){ //修改
            $name = $_POST['name'];
            $value = $_POST['value'];
            $query = "select * from whw_supplement where id=".getInt($id);
            $supplement = $objDBCD14->queryUniqueObject($query);
            $query = "update whw_supplement set ".$name." = ".quote($value)." where id=".getInt($id);
            $res = $objDBCD14->execute($query);
            if($res){
                $query = "insert into whw_supplement_log (user_id,supplement_id,name,content,createtime) values (".getInt($user['id']).",".getInt($id).",".quote($name).",".quote($value).",".time().")";
                $objDBCD14->execute($query);
                $msg = "修改成功";
            } else {
                $error = true;
                $msg = "未作任何修改";
            }
        } else if($action == 'remark'){ //修改
            $date = $_POST['date'];
            $remark = $_POST['remark'];
            $query = "update whw_settlement_admin set remark = ".quote($remark)." where date=".quote($date);
            $res = $objDBCD14->execute($query);
            $msg = "修改成功";
        } else if($action == 'settlement'){ //修改
            $date = $_POST['date'];
            $online_money = $_POST['online_money'];
            $money = $_POST['money'];
            $supplement_money_1 = $_POST['supplement_money_1'];
            $supplement_money_2 = $_POST['supplement_money_2'];
            $income_money = $_POST['income_money'];
            $id = $_POST['id'];
            $query = "update whw_settlement_admin set status = 1, online_money = ".getFloat($online_money).", money =".getFloat($money).",supplement_money_1 = ".getFloat($supplement_money_1).",supplement_money_2 = ".getFloat($supplement_money_2).",income_money = ".getFloat($income_money).",updatetime = ".time()." where id = ".getInt($id);
            $res = $objDBCD14->execute($query);
            $msg = "结算成功";
        }
        echo json_encode(['code'=>$error ? 0 : 1,'msg'=>$msg]);
        exit;
    }
    if($_GET['date']){
        $date = $_GET['date'];
    } else {
        $date = date("Y-m-d",time());
    }
    $date_start = strtotime($date." 00:00:00");
    $date_end = strtotime($date." 23:59:59");
        // 获取管理1的结算
    $query = "select a.*,user.username from whw_settlement_admin a inner join whw_user user on a.user_id = user.id where date = ".quote($date)." and user_id = 1";
    $user_1 = $objDBCD14->queryUniqueObject($query);
    if(!$user_1){
        $query_add = "insert into whw_settlement_admin (user_id,date,createtime) values (1,".quote($date).",".time().")";
        $objDBCD14->execute($query_add);
        $user_1 = $objDBCD14->queryUniqueObject($query);
    }
    $user_1 = json_decode(json_encode($user_1,JSON_UNESCAPED_UNICODE),true);
    // 获取管理2的结算
    $query = "select a.*,user.username from whw_settlement_admin a inner join whw_user user on a.user_id = user.id where date = ".quote($date)." and user_id = 2";
    $user_2 = $objDBCD14->queryUniqueObject($query);
    if(!$user_2){
        $query_add = "insert into whw_settlement_admin (user_id,date,createtime) values (2,".quote($date).",".time().")";
        $objDBCD14->execute($query_add);
        $user_2 = $objDBCD14->queryUniqueObject($query);
    }
    $user_2 = json_decode(json_encode($user_2,JSON_UNESCAPED_UNICODE),true);
    // 查询订单列表
    $query = "select a.*,user.username from whw_supplement a inner join whw_user user on a.user_id = user.id  where a.createtime BETWEEN ".$date_start. " and ".$date_end." order by a.id desc";
    $rows = $objDBCD14->query($query);
    $supplementList = [];
    $keys = ["content","money","imgs"];
    if ($rows->num_rows) {
        foreach ($rows as $key => $value) {
            $supplement = json_decode(json_encode($value,JSON_UNESCAPED_UNICODE),true);
            if($supplement['imgs']){
                $supplement['imgs'] = explode(",",$supplement['imgs']);
            } else {
                $supplement['imgs'] = [];
            }
            for($i = 0;$i < count($keys);$i++){
               $query = "select user.username from whw_supplement_log log inner join whw_user user on log.user_id = user.id where log.supplement_id=".getInt($supplement['id'])." and log.name = ".quote($keys[$i])." order by log.id desc";
               $log = $objDBCD14->queryUniqueObject($query);
               $supplement[$keys[$i]."_user"] =  $log->username;
            }
            $supplementList[] =  $supplement;
            if(!$user_1['status'] && $supplement['user_id'] == 1){
                if($supplement['type'] == 1){
                   $user_1['supplement_money_1'] += $value['money'];  
                } else {
                   $user_1['supplement_money_2'] += $value['money'];  
                }
            } else if(!$user_2['status'] && $value['user_id'] == 2){
                if($supplement['type'] == 1){
                   $user_2['supplement_money_1'] += $value['money'];  
                } else {
                   $user_2['supplement_money_2'] += $value['money'];  
                }
            }
        }  
    }
    // 不是今天则读取师傅数据
    $settlementList = [];
    $wait_settle = false;
    if($date != date("Y-m-d")){
        $query = "select a.*,user.username,admin.username as admin_username from whw_settlement a inner join whw_user user on a.user_id = user.id left join whw_user admin on a.admin_id = admin.id where a.date =".quote($date)." order by a.id desc";
        $rows = $objDBCD14->query($query);
        if ($rows->num_rows) {
            foreach ($rows as $key => $value) {
                $settlementList[] = $value; 
                if(!$wait_settle && !$value['admin_deal']){
                    $wait_settle = true;
                }
                if(!$user_1['status'] && $value['admin_id'] == 1){
                    $user_1['money'] += $value['pay_money'];
                    $user_1['online_money'] += $value['online_money'];
                } else if(!$user_2['status'] && $value['admin_id'] == 2){
                    $user_2['money'] += $value['pay_money'];
                    $user_2['online_money'] += $value['online_money'];
                }
            }
        }
    }
    if(!$user_1['status']){
        $user_1['income_money'] = $user_1['money'] + $user_1['supplement_money_1'] - $user_1['supplement_money_2'];
    }
    if(!$user_2['status']){
        $user_2['income_money'] = $user_2['money'] + $user_2['supplement_money_1'] - $user_2['supplement_money_2'];
    }
    $ave = ($user_1['income_money'] + $user_2['income_money'])/2;
    if($user_1['income_money'] >  $ave){
        $cha = bcsub($user_1['income_money'],$ave,2);
        $text = $user_1['username']."需向".$user_2['username']."转".$cha."元";
    } else {
        $cha = bcsub($user_2['income_money'],$ave,2);
        $text = $user_2['username']."需向".$user_1['username']."转".$cha."元";
    }
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>订单管理</title>
    <!-- 引入 layui.css -->
    <link rel="stylesheet" href="./layui/css/layui.css">
    <style>
        body{
           background: #f8f8f8; 
           height:100%;
        }
        .container{
            margin: 0;
        }
        .flex{
            display: flex;
        }
        .align-center{
            align-items: center;
        }
        .flex-1{
            flex: 1;
        }
        .header{
            background: #e64340;
            padding: 10px;
            color: #fff;
        }
        .header .user-info{
            display: flex;
            align-items: center;
        }
        .header .user-info .username{
            flex: 1;
            margin: 0 10px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: 18px;
            color: #fff;
        }
        .avatar{
            width: 60px;
            height: 60px;
            border-radius: 50%;
        }
        .btn-section a{
            display: block;
            background: unset;
            padding: 5px 0;
            color: #fff;
            cursor: pointer;
            font-weight: 500;
        }
        .list{
            padding: 10px;
        }
        .list .item{
            background: #fff;
            padding: 15px;
            border-radius: 5px;
            margin: 10px 0;
        }
        .list .item .face-row .face-col{
           display: inline-block; 
           margin: 0 5px 5px 0;
           font-size: 12px;
        }
        .list .item .face-row .face-col .layui-input{
            display: inline-block; 
            width: 40px;
            height: 25px;
            padding-left: 0;
            text-align: center;
        }
        .edit-btn{
            margin-left: 5px;
        }
        .edit-user{
            color: red;
            font-size: 12px;
            /*text-align: center;*/
        }
        .layer-photos img{
            width: 30px;
            height: 30px;
            margin: 0 2px;
        }
         .images{
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 5px 10px;
        }
        .images .item{
            width: 33.33%;
            min-width: 33.33%;
            max-width: 33.33%;
            position: relative;
            margin-top: 5px;
        }
        .images .item img{
            width: calc(26vw - 10px);
            height: calc(26vw  - 10px);
            border-radius: 5px;
        }
        .images .item i{
            position: absolute;
            top: 5px;
            right: 5px;
        }
        .list-settlement .edit-btn{
            display: none !important;
        }
        .extra{
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-top: 10px;
            color: #333;
        }
        .order-add{
            color: #fff;
            margin-right: 10px;
            font-weight: 900 .;
        }
    </style>
</head>
<body ontouchstart>
    <div class="container" id="container">
        <header class="header">
            <div class="user-info">
                <a href='./setting.php'>
                  <img src="<?=$user['avatar'] ? $user['avatar']: '/images/avatar.png' ?>" class="avatar" />
                </a>
                <a href='./setting.php' class="username">
                    <div style="font-weight: 500"><?=$user['username']?></div>
                    <div style="margin-top: 5px;font-size: 14px"><?=$user['phone']?></div>
                </a>
                <div class="btn-section">
                     <a href='./index.php'>订单管理</a>
                    <a href='./worker-list.php'>师傅管理</a>
                </div>
            </div>
            <form class="layui-form" action="">
                <div class="extra">
                    <div class="flex-1">
                        <a href="javascript:void(0)" class="order-add" data-type='1'>
                           补充收入
                        </a>
                        <a href="javascript:void(0)" class="order-add" data-type="2">
                           补充支出
                        </a>
                    </div>
                    <div style="width: 100px">
                        <input type="text" class="layui-input" id="date" value="<?= $date ?>"
                        style="height:32px">
                    </div>
                </div>
            </form>
        </header>
        <main>
            <?php if(count($supplementList) || count($settlementList)) { ?>
            <div class="list <?= $settlement['admin_deal'] ? 'list-settlement' : '' ?> ">
                <?php if($date != date("Y-m-d",time())){ ?>
                <div class="item">
                    <div style="display: flex;align-items:center;justify-content:space-between">
                        <div>今日小结</div>
                        <div><?=$date?></div>
                        <div>
                            <?php if($settlement['admin_deal'] == 0) { ?>
                                <span>待结算</span>
                            <?php } else { ?>
                                <span>已结算</span>
                            <?php } ?>
                        </div>
                    </div>
                    <?php if($wait_settle){ ?>
                        <div class="flex align-center"
                        style="margin-top: 10px;border-top: 1px solid #f7f7f7;padding-top: 10px;justify-content:space-between">
                            <div class="flex-1"
                            style="text-align:center;color: red">师傅端未结算完</div>
                        </div>
                    <?php } else {?>
                        <div 
                         style="margin-top: 10px;border-top: 1px solid #f7f7f7;padding-top: 10px;justify-content:space-between">
                            <div class="flex" style="font-size:15px;font-weight: 900">
                                <div style="margin-right: 10px"><?=$user_1['username']?></div>
                                <?php if($user_1['status']) {?>
                                    <div>
                                       已确认
                                    </div>
                                <?php }else { ?>
                                    <div style="color: red">
                                       未确认
                                    </div>
                                <?php } ?>
                            </div>
                            <div class="flex align-center"
                            style="margin-top: 10px">
                                <div class="flex align-center">
                                    <div>订单收钱：</div>
                                    <div class="flex-1 value"><?=$user_1['money']?>元</div>
                                </div>
                                <div class="flex align-center"
                                style="margin-left: 10px">
                                    <div>线上收款</div>
                                    <div class="flex-1 value"><?=$user_1['money']?>元未计入</div>
                                </div>
                            </div>
                            <div class="flex align-center"
                            style="margin-top: 10px">
                                <div class="flex align-center">
                                    <div>补充收钱：</div>
                                    <div class="flex-1 value"><?=$user_1['supplement_money_1']?>元</div>
                                </div>
                                <div class="flex align-center"
                                style="margin-left: 10px">
                                    <div>补充支出：</div>
                                    <div class="flex-1 value"><?=$user_1['supplement_money_2']?>元</div>
                                </div>
                            </div>
                            <div class="flex align-center"
                            style="margin-top: 10px">
                                <div class="flex align-center">
                                    <div>实际收钱：</div>
                                    <div class="flex-1 value"><?=$user_1['income_money']?>元</div>
                                </div>
                            </div>
                        </div>
                        <div 
                         style="margin-top: 10px;border-top: 1px solid #f7f7f7;padding-top: 10px;justify-content:space-between">
                           <div class="flex" style="font-size:15px;font-weight: 900">
                                <div style="margin-right: 10px"><?=$user_2['username']?></div>
                                <?php if($user_2['status']) {?>
                                    <div>
                                       已确认
                                    </div>
                                <?php }else { ?>
                                    <div style="color: red">
                                       未确认
                                    </div>
                                <?php } ?>
                            </div>
                            <div class="flex align-center"
                            style="margin-top: 10px">
                                <div class="flex align-center">
                                    <div>订单收钱：</div>
                                    <div class="flex-1 value"><?=$user_2['money']?>元</div>
                                </div>
                                <div class="flex align-center"
                                style="margin-left: 10px">
                                    <div>线上收款</div>
                                    <div class="flex-1 value"><?=$user_2['money']?>元未计入</div>
                                </div>
                            </div>
                            <div class="flex align-center"
                            style="margin-top: 10px">
                                <div class="flex align-center">
                                    <div>补充收钱：</div>
                                    <div class="flex-1 value"><?=$user_2['supplement_money_1']?>元</div>
                                </div>
                                <div class="flex align-center"
                                style="margin-left: 10px">
                                    <div>补充支出：</div>
                                    <div class="flex-1 value"><?=$user_2['supplement_money_2']?>元</div>
                                </div>
                            </div>
                            <div class="flex align-center"
                            style="margin-top: 10px">
                                <div class="flex align-center">
                                    <div>实际收钱：</div>
                                    <div class="flex-1 value"><?=$user_2['income_money']?>元</div>
                                </div>
                            </div>
                        </div>
                        <div 
                         style="margin-top: 10px;border-top: 1px solid #f7f7f7;padding-top: 10px;justify-content:space-between">
                            <div style="text-align:center;color: red"><?=$text?></div>
                            <form class="layui-form layui-form-pane remark-form" action="">
                                <input type="hidden" name="date" value="<?=$date?>" />
                                <div class="flex align-center"
                                style="margin-top: 10px;border-top: 1px solid #f7f7f7;padding-top: 10px;justify-content:center">
                                    <div>备注：</div>
                                    <textarea name="remark" placeholder="请输入备注" required class="layui-textarea" style="min-height: 30px;flex: 1;margin:0 10px 0 10px"><?=$user_1['remark']?></textarea> 
                                    <button class="layui-btn layui-btn-primary">提交</button>
                                </div>
                            </form>
                            <?php 
                                if(!$user_1['status'] && $user_1['user_id'] == $user['id']){
                            ?>
                                <form class="layui-form layui-form-pane settlement-form" action="">
                                    <input type="hidden" name="online_money" value="<?=$user_1['online_money']?>" />
                                    <input type="hidden" name="money" value="<?=$user_1['money']?>" />
                                    <input type="hidden" name="supplement_money_1" value="<?=$user_1['supplement_money_1']?>" />
                                    <input type="hidden" name="supplement_money_2" value="<?=$user_1['supplement_money_2']?>" />
                                    <input type="hidden" name="income_money" value="<?=$user_1['income_money']?>" />
                                    <input type="hidden" name="id" value="<?=$user_1['id']?>" />
                                    <div style="text-align:center;margin-top: 10px">
                                        <button class="layui-btn layui-btn-fluid settlement-btn">确认无误</button>
                                    </div>
                                </form>
                            <?php } ?>
                        </div>
                    <?php } ?>
                </div>
                <?php } ?>
                <?php for($i = 0;$i < count($supplementList);$i++) { ?>
                    <div class="item">
                        <div style="display: flex;align-items:center;justify-content:space-between">
                            <div><?=$supplementList[$i]['username']?></div>
                            <div><?=date("Y-m-d H:i:s",$supplementList[$i]['createtime'])?></div>
                            <div>
                                <?php if($supplementList[$i]['type'] == 1) { ?>
                                    <span>补充收入</span>
                                <?php } else if($supplementList[$i]['type'] == 2) { ?>
                                    <span>补充支出</span>
                                <?php } ?>
                            </div>
                        </div>
                        <div class="flex" style="margin-top: 10px;border-top: 1px solid #f7f7f7;padding-top: 10px">
                            <div class="flex flex-1">
                                <div>金额：<div class="edit-user"><?=$supplementList[$i]['money_user']?></div></div>
                                <div class="value"><?=$supplementList[$i]['money']?></div>
                                <button class="layui-btn layui-btn-xs layui-btn-primary edit-btn"
                                data-name="money" data-id="<?=$supplementList[$i]['id']?>">修改</button>
                            </div>
                            <div class="flex flex-1 align-center"
                            style="margin-left: 10px">
                            </div>
                        </div>
                        <div class="flex" style="margin-top: 10px;">
                            <div>说明：<div class="edit-user"><?=$supplementList[$i]['content_user']?></div></div>
                            <div class="flex-1 value"><?=$supplementList[$i]['content']?></div>
                            <button class="layui-btn layui-btn-xs  layui-btn-primary edit-btn" data-name="content" data-id="<?=$supplementList[$i]['id']?>">修改</button>
                        </div>
                        <div class="flex" style="margin-top: 10px;">
                            <div>图片：<div class="edit-user"><?=$supplementList[$i]['imgs_user']?></div></div>
                            <div class="flex-1 layer-photos value">
                                <?php for($img_i = 0;$img_i < count($supplementList[$i]['imgs']);$img_i++){ ?>
                                <img  layer-src="<?=$supplementList[$i]['imgs'][$img_i]?>" src="<?=$supplementList[$i]['imgs'][$img_i]?>" />
                                <?php } ?>
                            </div>
                            <button class="layui-btn layui-btn-xs  layui-btn-primary edit-btn" data-name="imgs" data-id="<?=$supplementList[$i]['id']?>">修改</button>
                        </div>
                    </div>
                <?php } ?>
                <?php for($i = 0;$i < count($settlementList);$i++) { ?>
                    <div class="item">
                        <div style="display: flex;align-items:center;justify-content:space-between">
                            <div><?=$settlementList[$i]['username']?></div>
                            <div><?=$settlementList[$i]['date']?></div>
                            <div>
                                <?php if($settlementList[$i]['admin_deal'] == 0) { ?>
                                    <span>师傅端未结算</span>
                                <?php } else if($settlementList[$i]['admin_deal'] == 1) { ?>
                                    <span>师傅端已结算</span>
                                <?php } ?>
                            </div>
                        </div>
                        <div class="flex" style="margin-top: 10px;border-top: 1px solid #f7f7f7;padding-top: 10px">
                            <?php if($settlementList[$i]['admin_deal'] == 1) { ?>
                            <div>
                                <?=$settlementList[$i]['admin_username']?>收款<?=$settlementList[$i]['pay_money']?>元
                            </div>
                            <div style="margin-left: 10px">
                                线上收款<?=$settlementList[$i]['online_money']?>元未计入
                            </div>
                            <?php } ?>
                        </div>
                    </div>
                <?php } ?>
            </div>
            <?php } else { ?>
            <img src="./images/data-empty.png" style="width: 200px;height:auto;display:block;margin: 10vh auto" />
            <?php } ?>
        </main>
    </div>
    <!-- 引入 layui.js -->
    <script src="./layui/layui.js"></script>
    <script>
        layui.use(['layer', 'form','laydate','upload'], function(){
            var  $ = layui.$,  layer = layui.layer,form = layui.form,laydate = layui.laydate,upload = layui.upload;
            // 日期
            laydate.render({
                elem: '#date',
                done: function(value, date, endDate){
                   location.href = 'finance.php?date='+value
                }
            })
            // 图片
            layer.photos({
              photos: '.layer-photos'
              ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
            // 删除
            $(document).on('click', '.del-img', function() {
                $(this).parent().remove()
            })
            // 创建订单
            $(".order-add").click(function(){
                var type = $(this).data("type")
                layer.open({
                  type: 2, 
                  title: type == 1 ? "补充收入" : '补充支出',
                  area: ['90vw','90vh'],
                  content: './supplement-add.php?type='+type,
                  shadeClose: false,
                  fixed: true,
                  offset: 'auto', // 自动偏移
                  success: function(layero, index){
                    
                  },
                });
            })
            // 修改
            $(document).on('click', '.edit-btn', function() {
                var obj = $(this)
                var name = obj.data("name")
                var id = obj.data("id")
                var value = obj.siblings(".value").text()
                var title = ""
                var formType = 0
                switch(name){
                    case 'content':
                        title = "说明"
                        formType = 2
                    break;
                    case 'money':
                        title = "金额"
                        formType = 0
                    break;
                    case 'imgs':
                        title = "修改图片"
                        formType = 20
                    break;
                }
                if(formType == 20){
                    var imgsHtml = '<div class="images">'
                    obj.siblings(".value").find("img").each(function(){
                        var imgUrl = $(this).attr("src")
                        imgsHtml += '<div class="item"><img class="layui-img" src="'+imgUrl+'"/><i class="layui-icon layui-icon-close-fill del-img"></i></div>'
                    })
                    imgsHtml += '</div>'
                    imgsHtml += ' <div class="layui-input-block" style="margin-top: 10px;margin-left: 10px;"><button type="button" class="layui-btn" id="upload"><i class="layui-icon">&#xe67c;</i>上传图片</button></div>'
                    layer.open({
                      type: 1, 
                      title,
                      area: ['80vw','60vh'],
                      content: imgsHtml,
                      btn: ['保存', '取消'],
                      success: function(){
                        var uploadInst = upload.render({
                            elem: '#upload' //绑定元素
                            ,url: 'upload.php' //上传接口
                            ,accept: "images"
                            ,multiple: true
                            ,done: function(res){
                              if(res.code == 1){
                                $(".images").append('<div class="item"><img class="layui-img" src="'+res.data.src+'"/><i class="layui-icon layui-icon-close-fill del-img"></i></div>')   
                              }
                              //上传完毕回调
                            }
                            ,error: function(){
                              //请求异常回调
                            }
                        });  
                      },
                      yes: function(lay_index,layero){
                        // 获取图片
                        var imgs = []
                        var html = ''
                        layero.find('.layui-img').each(function(){
                            var imgUrl = $(this).attr("src")
                            imgs.push(imgUrl)
                            html += '<img layer-src="'+imgUrl+'" src="'+imgUrl+'" />'
                        })
                        var value = imgs.join(",") 
                        $.post("finance.php",{id,action:'edit',name: "imgs",value},function(res){
                            res = JSON.parse(res)
                            layer.msg(res.msg);
                            if(res.code == 1){
                                obj.siblings(".value").html(html)
                                layer.close(lay_index);
                                location.reload()
                            }
                        })
                      }
                    });
                }else {
                    layer.prompt({
                      formType,
                      value,
                      title,
                      area: formType == 1 ? ['80vw', '60px']  : ['80vw', '100px']
                    }, function(value, index, elem){
                        $.post("finance.php",{id,action:'edit',name,value},function(res){
                            res = JSON.parse(res)
                            layer.msg(res.msg);
                            if(res.code == 1){
                                obj.siblings(".value").text(value)
                                layer.close(index);
                                location.reload()
                            }
                        })
                    });
                }
            })
            // 修改备注
            $(".remark-form").submit(function(){
                var formValues = $(this).serializeArray();
                var param = {}
                $.each(formValues, function(i, field){
                   param[field.name] = field.value
                });
                param.action = "remark"
                $.post("finance.php",param,function(res){
                    res = JSON.parse(res)
                    layer.msg(res.msg);
                    if(res.code == 1){
                        setTimeout(function(){
                          location.reload()
                        },1000)
                    }
                })
                return false
            })
            // 确认结算
            $(".settlement-form").submit(function(){
                var formValues = $(this).serializeArray();
                var param = {}
                $.each(formValues, function(i, field){
                   param[field.name] = field.value
                });
                param.action = "settlement"
                $.post("finance.php",param,function(res){
                    res = JSON.parse(res)
                    layer.msg(res.msg);
                    if(res.code == 1){
                        setTimeout(function(){
                          location.reload()
                        },1000)
                    }
                })
                return false
            })
        })
    </script>  
</body>
</html>